#include <bits/stdc++.h>
using namespace std;
int T;
int n;
char a[21];
int sa[21];
int u[21],d[21];
bool cmp(int x,int y)
{
	int i = 0;
	while(x + i <= n && y + i <= n && a[x + i] == a[y + i])
		i++;
	if(x + i <= n && y + i <= n)
		return a[x + i] < a[y + i];
	return x > y;
}
bool Check()
{
	for(int i = 1;i <= n;i++)
	{
		int k = 0;
		while(i - k > 0 && i + k <= n && a[i - k] == a[i + k])
			k++;
		k = (k - 1) * 2 + 1;
		if(k != u[i])
			return 0;
	}
	for(int i = 1;i < n;i++)
	{
		int k = 0;
		while(i - k >= 0 && i + k < n && a[i - k] == a[i + k + 1])
			k++;
		k = k * 2;
		if(k != d[i])
			return 0;
	}
	for(int i = 1;i < n;i++) if(!cmp(sa[i],sa[i + 1]))
		return 0;
	for(int i = 1;i <= n;i++)
		cout << a[i];
	cout << "\n";
	return 1;
}
bool DFS(int deep)
{
	if(deep > n)
		return Check();
	for(char c = 'a';c < 'a' + n;c++)
	{
		a[deep] = c;
		if(DFS(deep + 1))
			return 1;
	}
	return 0;
}
int l[1000011];
char ans[1000011];
void SolveA()
{
	for(int i = 1;i <= n;i++)
		l[i] = i;
	for(int i = 1;i <= n;i++)
	{
		int k = (u[i] - 1) / 2;
		l[i + k] = min(l[i + k],i - k);
	}
	for(int i = 1;i < n;i++)
	{
		int k = d[i] / 2;
		l[i + k] = min(l[i + k],i - k + 1);
	}
	char res = 'a';
	for(int i = n;i;i--)
	{
		ans[i] = res;
		if(l[i] == i)
		{
			if(res == 'z')
			{
				cout << -1 << "\n";
				continue;
			}
			res++;
		}else if(l[i - 1] != l[i])
		{
			cout << -1 << "\n";
			continue;
		}
	}
	l[n + 1] = n + 1;
	for(int i = 1;i <= n;i++)
	{
		int k = (u[i] - 1) / 2;
		if(l[i - k] != i - k && l[i + k + 1] != i + k + 1)
		{
			cout << -1 << "\n";
			continue;
		}
	}
	for(int i = 1;i < n;i++)
	{
		int k = d[i] / 2;
		if(l[i - k] != i - k && l[i + k + 1] != i + k + 1)
		{
			cout << -1 << "\n";
			continue;
		}
	}
	for(int i = 1;i <= n;i++)
		cout << ans[i];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
	cin >> T;
	while(T--)
	{
		cin >> n;
		bool A = 1;
		for(int i = 1;i <= n;i++)
			cin >> sa[i],A |= ((sa[i]++) + i == n);
		for(int i = 1;i < n;i++)
			cin >> u[i] >> d[i];
		cin >> u[n];
		if(A && n > 8)
		{
			SolveA();
			continue;
		}
		if(!DFS(1))
			cout << -1 << '\n';
	}
    return 0;
}
